package com.jzy.message.activities.base;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import com.jzy.message.util.common.CommUtility;

import org.xutils.common.Callback.CommonCallback;
import org.xutils.http.RequestParams;
import org.xutils.x;

public abstract class BaseActivity extends Activity {
	public BaseActivity thisActivity;
	public Dialog dlgWaiting;
	public void requestDataGet(final int flag,final Context context,RequestParams params)
	{
		//由于linux服务端不能识别自带的cookie，所以要手动添加cookie
		if(!AppConfig.sCurrentCookie.equals(""))
		{
			params.setUseCookie(false);
			params.addHeader("Cookie",AppConfig.sCurrentCookie);
		}
		x.http().get(params, new CommonCallback<String>() {
			@Override
			public void onCancelled(CancelledException arg0) {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
					CommUtility.showmsg(context, "数据加载取消");
				}
			}
			@Override
			public void onError(Throwable arg0, boolean arg1) {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
					CommUtility.showmsg(context, "数据加载错误"+arg0);
				}
			}
			@Override
			public void onFinished() {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
				}
			}
			@Override
			public void onSuccess(String arg0) {
				dlgWaiting.hide();
				ParseData(flag, arg0);
			}
		});
	}
	public void requestDataPost(final int flag,final Context context,RequestParams params)
	{
		if(!AppConfig.sCurrentCookie.equals(""))
		{
			params.setUseCookie(false);
			params.addHeader("Cookie",AppConfig.sCurrentCookie);
		}
		x.http().post(params, new CommonCallback<String>() {
			@Override
			public void onCancelled(CancelledException arg0) {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
					CommUtility.showmsg(context, "数据加载取消");
				}
			}
			@Override
			public void onError(Throwable arg0, boolean arg1) {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
					CommUtility.showmsg(context, "数据加载错误"+arg0);
				}
			}
			@Override
			public void onFinished() {
				if(dlgWaiting!=null&&dlgWaiting.isShowing())
				{
					dlgWaiting.hide();
				}
			}
			@Override
			public void onSuccess(String arg0) {
				dlgWaiting.hide();
				ParseData(flag, arg0);
			}
		});
	}
	public void ParseData(int flag,String jsonstr)
	{

	}
}
